package com.yx.backstage.handler;

import com.alibaba.fastjson.JSON;
import com.yx.backstage.config.global.CommonResult;
import com.yx.backstage.util.WebUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author YangXiong
 */
public class LocalAuthenticationFailureHandler implements AuthenticationFailureHandler {

  @Override
  public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) {
    CommonResult<String> result = new CommonResult<>("账号或者密码错误");
    String json = JSON.toJSONString(result);
    WebUtils.renderString(response,json);
  }
}
